<?php
class Persion{
    public $name;
    public $age;
}
$person=new Persion();
$person->name="Alice";
$person->age= 25;
$variable="name";
echo $person->$variable;
$variable="age";
echo $person->$variable;